/*
 * property_base.h
 *
 *  Created on: 2011-8-7
 *      Author: wangchao
 */

#ifndef PROPERTY_BASE_H_
#define PROPERTY_BASE_H_

// access
struct ReadOnly
{

};

struct WriteOnly
{

};

struct ReadWrite
{

};

// host
struct NoHost
{

};

// value type
struct Unknown
{

};
// store policy
struct PointToVar
{

};

struct Storage
{

};

template<int v>
struct Int2Type
{
    enum
    {
        value = v
    };
};

template<typename T>
struct Type2Type
{
    typedef T OrignalType;
};

template<bool flag, typename T, typename U>
struct Select
{
    typedef T Result;
};
template<typename T, typename U>
struct Select<false, T, U>
{
    typedef U Result;
};

template<typename _from, typename _to>
struct Convert
{
    typedef char Small;
    class Big
    {
        char dummy[2];
    };

    static Small Test(_to);
    static Big Test(... );
    static _from MakeT();
public:
    enum
    {
        exists = (sizeof(Test(MakeT())) == sizeof(Small))
    };
    enum
    {
        exists2Way = exists && Convert<_to, _from>::exists
    };
    enum
    {
        sameType = false
    };
};
template<typename _from>
struct Convert<_from, _from>
{
    enum
    {
        exists = 1
    };
    enum
    {
        exists2Way = 1
    };
    enum
    {
        sameType = 1
    };
};

template<bool valid>
struct ArraySize
{
    enum
    {
        value = valid
    };
};
template<bool valid>
struct AssertHelper
{
    char value[valid];
};

#define IS_SAME_TYPE( a, b )  (Convert<a,b>::sameType)
#define C_ASSERT( value ) AssertHelper<value>()

template< typename message,bool expr> struct CompileTimeChecker
{
    CompileTimeChecker();
    //CompileTimeChecker(...);
};
template<typename noerror> struct CompileTimeChecker<noerror, true>
{

};

#define STATIC_CHECK( expr, msg )\
{\
    class Error_##msg{};\
    sizeof( CompileTimeChecer<(expr)>( Error_##msg() ) );\
}
#endif /* PROPERTY_BASE_H_ */
